var classtype = {};
// Populate the classtype map
"Boolean Number String Function Array Date RegExp Object".split(" ").forEach((name, i) => {
    classtype["[object " + name + "]"] = name.toLowerCase();
});
export function typeName(obj) {
  return obj == null ? String(obj) : (classtype[Object.prototype.toString.call(obj)] || "object");
}


// 解析url
export function parseQuery(url) {
  let queryObj = {};
  let reg = /[?&]([^=&#]+)=([^&#]*)/g;
  let querys = url.match(reg);
  if (querys) {
    for (let i in querys) {
      let query = querys[i].split('=');
      let key = query[0].substr(1);
      let value = query[1];
      queryObj[key] ? (queryObj[key] = [].concat(queryObj[key], value)) : (queryObj[key] = value);
    }
  }
  return queryObj;
};

export const formatDataToUrl = function(url, data) {
  let str = '',
    q = '';
  for (let i in data) {
    q = data[i];
    if (typeof data[i] === 'object') q = JSON.stringify(data[i]);
    if(q !== '' && typeof q !== 'undefined' && q !== null) str += '&' + i + '=' + encodeURIComponent(q);
  }
  if (!str) return url;
  return url + '?' + str.substr(1);
}